﻿using BlogEngine.Gallery.Data;
using NuGet.Server;
using System.Web;

public class PackageExtraService : IPackageService
{
    public PackageExtraService(PackageService packageService)
    {
        _PackageService = packageService;
    }

    private readonly PackageService _PackageService;

    public void CreatePackage(HttpContextBase context)
    {
        _PackageService.CreatePackage(context);
    }

    public void DeletePackage(HttpContextBase context)
    {
        _PackageService.DeletePackage(context);
    }

    public void DownloadPackage(HttpContextBase context)
    {
        var x = context.Request.Url.Segments.Length;
        if (x > 2)
        {
            var pVersion = context.Request.Url.Segments[x - 1];
            var pName = context.Request.Url.Segments[x - 2].Replace("/", "");
            var pkg = pName + "." + pVersion;

            Repository.UpdateCount(pkg);
        }

        _PackageService.DownloadPackage(context);
    }

    public void PublishPackage(HttpContextBase context)
    {
        _PackageService.PublishPackage(context);
    }
}